import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:gourmet/color/hex.dart';
import 'package:gourmet/components/mine/collect.dart';
import 'package:gourmet/extensions/ex_widget.dart';
import 'package:gourmet/ui/keep_alive.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/styles.dart';
import 'package:gourmet/utils/tools.dart';

class MineCollectController extends GetxController
    with GetTickerProviderStateMixin {
  late TabController controller;
  List<String> tabs = [
    '商品收藏',
    '店铺收藏',
  ];

  @override
  void onInit() {
    controller = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    controller.dispose();
    super.onClose();
  }
}

class MineCollectPage extends GetView<MineCollectController> {
  const MineCollectPage({super.key});

  @override
  Widget build(BuildContext context) {
    return MediaQuery.removeViewPadding(
      context: context,
      removeBottom: true,
      removeLeft: true,
      removeRight: true,
      removeTop: true,
      child: Scaffold(
        backgroundColor: HexColor(ColorsUtils.colorF7f7),
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(84 + Get.mediaQuery.padding.top),
          child: AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark,
            child: Container(
              color: Colors.white,
              child: Column(
                children: [
                  Padding(
                    padding: EdgeInsets.only(top: Get.mediaQuery.padding.top),
                    child: SizedBox(
                      height: 44,
                      child: Stack(
                        children: [
                          Container(
                            alignment: Alignment.center,
                            height: 44,
                            child: Text(
                              '我的收藏',
                              style: StylesUtils.customTextStyle(
                                fontWeight: FontWeight.w700,
                                fontSize: StylesUtils.fontSize16,
                                color: ColorsUtils.color0000,
                              ),
                            ),
                          ),
                          Positioned(
                            top: 0,
                            left: 0,
                            child: Container(
                              width: 40,
                              height: 44,
                              alignment: Alignment.center,
                              child: Icon(
                                CupertinoIcons.chevron_back,
                                size: 20.sp,
                                color: HexColor(ColorsUtils.color0000),
                              ),
                            ).onTap(Get.back),
                          ),
                          Positioned(
                            right: 0,
                            top: 0,
                            child: SizedBox(
                              width: 80,
                              height: 44,
                              child: Column(
                                children: [
                                  Container(
                                    margin: const EdgeInsets.only(top: 5),
                                    alignment: Alignment.center,
                                    child: Icon(
                                      CupertinoIcons
                                          .arrow_right_arrow_left_circle_fill,
                                      color: HexColor(ColorsUtils.color0000),
                                      size: 20.sp,
                                    ),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 5),
                                    alignment: Alignment.center,
                                    child: Text(
                                      '切换地址',
                                      style: StylesUtils.customTextStyle(
                                        fontSize: StylesUtils.fontSize12,
                                        color: ColorsUtils.color0000,
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ).onTap(() {}),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 40,
                    alignment: Alignment.center,
                    child: ToolsUtils.getClientTabBar(
                      controller.tabs,
                      controller.controller,
                      indicatorMinWidth: 20,
                      indicatorWeight: 3,
                      isScrollable: false,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        body: TabBarView(
          controller: controller.controller,
          children: [
            KeepAliveWrapperView(
              child: const GoodsCollectView(),
              callback: () {
                Get.lazyPut(() => GoodsCollectController());
              },
            ),
            KeepAliveWrapperView(
              child: const StoreCollectView(),
              callback: () {
                Get.lazyPut(() => StoreCollectController());
              },
            ),
          ],
        ),
      ),
    );
  }
}
